//
//  AddExpectedWorkVC.m
//  MyProject
//
//  Created by jiaming yan on 2017/9/13.
//  Copyright © 2017年 yanjiaming. All rights reserved.
//

#import "AddExpectedWorkVC.h"
#import "TypePickerView.h"
//#import "MyCityListViewController.h"
//#import "MoreJobListVC.h"

@interface AddExpectedWorkVC ()
@property (weak, nonatomic) IBOutlet UITextField *jobNameTextField;
@property (weak, nonatomic) IBOutlet UITextField *jobTypeTextField;
@property (weak, nonatomic) IBOutlet UITextField *cityTextField;
@property (weak, nonatomic) IBOutlet UITextField *salaryTextField;

@property (copy, nonatomic) NSString *strType;
@property (copy, nonatomic) NSString *strSalaryCode;
@property (assign, nonatomic) NSInteger jobId;
@property (copy, nonatomic) NSString *strCityId;

@end

@implementation AddExpectedWorkVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationItem.title = @"期望工作";
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"保存" forState:UIControlStateNormal];
    [button setTitleColor:UIColorFromRGB(0x13bacd) forState:UIControlStateNormal];
    button.titleLabel.font = k15Font;
    button.frame = CGRectMake(0, 0, 40, 40);
    [button addTarget:self action:@selector(saveButtonClick) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *barItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]
                                       initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                                       target:nil action:nil];
    
    negativeSpacer.width = -10;
    self.navigationItem.rightBarButtonItems = @[negativeSpacer,barItem];
    if (IOS11Later) {
        button.contentHorizontalAlignment =UIControlContentHorizontalAlignmentRight;
    }
    [self setValues];
}

- (void)setValues{
    self.jobNameTextField.text = self.modelGetResume.expectedWork;
    self.jobId = [self.modelGetResume.expectedWorkCode integerValue];;
    self.jobTypeTextField.text = self.modelGetResume.expectedModel;
    self.strType = self.modelGetResume.expectedModelCode;
    self.cityTextField.text = self.modelGetResume.expectedWorkplace;
    self.strCityId = self.modelGetResume.expectedWorkplaceCode;
    self.salaryTextField.text = self.modelGetResume.expectedSalary;
    self.strSalaryCode = self.modelGetResume.expectedSalaryCode;
}

-(void)saveButtonClick{
    
    NSString *strAlert = @"";
    
    if (self.jobId ==0) {
        strAlert = @"请选择职位名称";
    }else if (self.strType.length == 0){
        strAlert = @"请选择全职/兼职";
    }else if (self.strCityId.length == 0){
        strAlert = @"请选择期望城市";
    }else if (self.strSalaryCode.length == 0){
        strAlert = @"请选择期望月薪";
    }
    if (strAlert.length != 0) {
        [CommonUtils showToast:strAlert];
        return;
    }

    NSLog(@"保存点击");
    //    NSString *strResumeId = self.str
    NSMutableDictionary *dicInfoParams = [[NSMutableDictionary alloc]initWithObjectsAndKeys:
                                          [NSString stringWithFormat:@"%zd",self.jobId],@"expectedWorkCode",
                                          self.strType,@"expectedModelCode",
                                          self.strCityId,@"expectedWorkplaceCode",
                                          self.strSalaryCode,@"expectedSalaryCode",
                                          nil];
    //简历id设置
    if (self.modelGetResume.resumeId != 0) {
        [dicInfoParams setObject:[NSString stringWithFormat:@"%zd",self.modelGetResume.resumeId] forKey:@"resumeId"];
    }
        //dicInfoParams转json
    NSString *strJson = [self DataToJsonString:dicInfoParams];
    
    [self showProgressWithView:self.view animated:YES];
    __weak typeof(self) weakSelf = self;
    [SendRequest updateResumeByParamWithUserInfoParams:strJson workExperienceParams:@"" eduExperienceParams:@"" valuesParams:@"" projectExperienceParams:@"" skillParams:@"" result:^(NSDictionary *result, NSError *error) {
        [weakSelf hideProgress:weakSelf.view animated:YES];
        result = [CommonUtils decryptDicWithResult:result];
        if([result[@"result"] integerValue] == 1)
        {
            [self.navigationController popViewControllerAnimated:YES];
        }else{
            [CommonUtils showToast:[result objectForKey:@"msg"]];
        }
        
    }];

}

- (IBAction)btnChooseCityOnClick:(id)sender {
//    MyCityListViewController *vc = [[MyCityListViewController alloc]init];
//    vc.citySelected = ^(NSString *cityName, NSString *cityId) {
//        NSLog(@"===%@,%@",cityId,cityName);
//        self.cityTextField.text = cityName;
//        self.strCityId = cityId;
//    };
//    [self.navigationController pushViewController:vc animated:YES];
}

- (IBAction)btnChooseJobOnClick:(id)sender {
//    MoreJobListVC *vc = [MoreJobListVC alloc];
//    vc.moreJobSelect = ^(DesiredJobHotJobList *model) {
//        self.jobNameTextField.text = model.jobName;
//        self.jobId = model.jobId;
//    };
//    [self.navigationController pushViewController:vc animated:YES];
}

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    __weak typeof(self) weakSelf = self;
   
    if (textField == self.jobTypeTextField) {
        [self.view endEditing:YES];
        TypePickerView *time = [[TypePickerView alloc]init];
        time.typeArr = @[@"全职",@"兼职",@"实习"];
        time.selectPicker = ^(NSString *typeStr){
            weakSelf.jobTypeTextField.text = typeStr;
            if ([typeStr isEqualToString:@"全职"]) self.strType = @"JOB_OCCUPATIONAL_PROPERTY_FULL_TIME";
            if ([typeStr isEqualToString:@"兼职"]) self.strType = @"JOB_OCCUPATIONAL_PROPERTY_PART_TIME";
            if ([typeStr isEqualToString:@"实习"]) self.strType = @"JOB_OCCUPATIONAL_PROPERTY_PRACTICE";
        };
        [time creatTypePickerView:self.view];
        return NO;
    }else if(textField == self.salaryTextField) {
        [self.view endEditing:YES];
        TypePickerView *time = [[TypePickerView alloc]init];
        time.typeArr = @[@"3K以下",@"3K-5K",@"5K-8K",@"8K-10K",@"10K-12K",@"12K-15K",@"15K以上",@"全部"];
        time.selectPicker = ^(NSString *typeStr){
            weakSelf.salaryTextField.text = typeStr;
            if ([typeStr isEqualToString:@"3K以下"]) self.strSalaryCode = @"JOB_EXPECTED_SALARY_LT_3K";
            if ([typeStr isEqualToString:@"3K-5K"]) self.strSalaryCode = @"JOB_EXPECTED_SALARY_LT_5K_GT_3K";
            if ([typeStr isEqualToString:@"5K-8K"]) self.strSalaryCode = @"JOB_EXPECTED_SALARY_LT_8K_GT_5K";
            if ([typeStr isEqualToString:@"8K-10K"]) self.strSalaryCode = @"JOB_EXPECTED_SALARY_LT_10K_GT_8K";
            if ([typeStr isEqualToString:@"10K-12K"]) self.strSalaryCode = @"JOB_EXPECTED_SALARY_LT_12K_GT_10K";
            if ([typeStr isEqualToString:@"12K-15K"]) self.strSalaryCode = @"JOB_EXPECTED_SALARY_LT_15K_GT_12K";
            if ([typeStr isEqualToString:@"15K以上"]) self.strSalaryCode = @"JOB_EXPECTED_SALARY_GT_15K";
            if ([typeStr isEqualToString:@"全部"]) self.strSalaryCode = @"JOB_EXPECTED_SALARY_ALL";
        };
        [time creatTypePickerView:self.view];
        return NO;
    }
    UIView *tempView = [self.view viewWithTag:909090901];
    [tempView removeFromSuperview];
    return YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
